package com.changgou.seckill.controller;

import com.changgou.entity.DateUtil;
import com.changgou.entity.Result;
import com.changgou.entity.SeckillStatus;
import com.changgou.entity.StatusCode;
import com.changgou.seckill.pojo.SeckillGoods;
import com.changgou.seckill.pojo.SeckillOrder;
import com.changgou.seckill.service.SeckillOrderService;
import com.changgou.seckill.task.MultiThreadingCreateOrder;
import com.github.pagehelper.PageInfo;

import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/
@Api(value = "SeckillOrderController")
@RestController
@RequestMapping("/seckillOrder")
@CrossOrigin
public class SeckillOrderController {

    @Autowired
    private SeckillOrderService seckillOrderService;


    /**
     * 添加秒杀订单
     */
    @RequestMapping(value = "/add")
    public Result add(String time, Long id,String userId) {
        seckillOrderService.add(time, id, userId);
        return new Result(true, StatusCode.OK, "正在排队...!");
    }

    @GetMapping(value = "/query")
    public Result queryStatus() {
        String username = "szitheima";
        SeckillStatus seckillStatus = seckillOrderService.queryStatus(username);
        if (seckillStatus != null) {
            new Result(true, StatusCode.OK, "查询状态成功！", seckillStatus);
        }
        return new Result(false, StatusCode.NOTFOUNDERROR, "抢单失败! ");
    }
}
